]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
fileUtils: Add helper for loading D-Bus XML from resource
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 6 Sep 2018 00:04:47 +0000 (02:04 +0200)
committerJonas Ådahl <jadahl@gmail.com>
Mon, 17 Sep 2018 07:34:49 +0000 (07:34 +0000)
Commit dbf993300a moved all inline D-Bus interface descriptions to template
strings so we can stop escaping line breaks.

Unfortunately that unveiled a grave bug in xgettext, which currently cannot
handle files that contain both backtick and slash characters - as a result,
translations from affected files have started to disappear as translators
run xgettext/msgmerge.

Instead of reverting the change and getting the crusty escaping back, we
will take this as an opportunity to stop inlining the XML altogether and
load it from a resource instead.

To facilitate that, add a small helper method that loads a D-Bus interface
description from a dedicated resource bundle.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/537

data/gnome-shell-dbus-interfaces.gresource.xml [new file with mode: 0644]
data/meson.build
js/misc/config.js.in
js/misc/fileUtils.js

diff --git a/data/gnome-shell-dbus-interfaces.gresource.xml b/data/gnome-shell-dbus-interfaces.gresource.xml
new file mode 100644 (file)
index 0000000..bc637ee
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/shell/dbus-interfaces">
+  </gresource>
+</gresources>
index e0b879cd1e391f6797212738f9c5ee717c47820d..31ac4514ec8840b20885e3fe0370e73fac9d4db5 100644 (file)
@@ -44,22 +44,22 @@ endforeach
 subdir('dbus-interfaces')
 subdir('theme')
 
-theme_resources = gnome.compile_resources(
-  'gnome-shell-theme', 'gnome-shell-theme.gresource.xml',
-  source_dir: 'theme',
-  dependencies: theme_deps,
-  gresource_bundle: true,
-  install: true,
-  install_dir: pkgdatadir
-)
-
-osk_layout_resources = gnome.compile_resources(
-  'gnome-shell-osk-layouts', 'gnome-shell-osk-layouts.gresource.xml',
-  source_dir: 'osk-layouts',
-  gresource_bundle: true,
-  install: true,
-  install_dir: pkgdatadir
-)
+data_resources = [
+  ['dbus-interfaces', []],
+  ['osk-layouts', []],
+  ['theme', theme_deps]
+]
+foreach resource : data_resources
+  gnome.compile_resources(
+    'gnome-shell-' + resource[0],
+    'gnome-shell-@0@.gresource.xml'.format(resource[0]),
+    source_dir: resource[0],
+    dependencies: resource[1],
+    gresource_bundle: true,
+    install: true,
+    install_dir: pkgdatadir
+  )
+endforeach
 
 perfconf = configuration_data()
 perfconf.set('datadir', datadir)
index 28bff96e4f04fac56c467dfc1d863901cb94d9de..065d7a0a2a17850893a261665627e016a96647fc 100644 (file)
@@ -14,6 +14,7 @@ var GETTEXT_PACKAGE = '@GETTEXT_PACKAGE@';
 var LOCALEDIR = '@datadir@/locale';
 /* other standard directories */
 var LIBEXECDIR = '@libexecdir@';
+var PKGDATADIR = '@datadir@/@PACKAGE_NAME@';
 var VPNDIR = '@vpndir@';
 /* g-i package versions */
 var LIBMUTTER_API_VERSION = '@LIBMUTTER_API_VERSION@'
index 036017e671d006c4738a84abb920813de14c3b9c..81cd92c941e0bda83164ca8f98e7f142f6f4f267 100644 (file)
@@ -3,6 +3,7 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Lang = imports.lang;
+const Config = imports.misc.config;
 const Params = imports.misc.params;
 
 function collectFromDatadirs(subdir, includeUserDir, processFile) {
@@ -70,3 +71,29 @@ function recursivelyMoveDir(srcDir, destDir) {
             recursivelyMoveDir(srcChild, destChild);
     }
 }
+
+let _ifaceResource = null;
+function loadInterfaceXML(iface) {
+    if (!_ifaceResource) {
+        // don't use global.datadir so the method is usable from tools
+        let path = Config.PKGDATADIR + '/gnome-shell-dbus-interfaces.gresource';
+        _ifaceResource = Gio.Resource.load(path);
+        _ifaceResource._register();
+    }
+
+    let xml = null;
+    let uri = 'resource:///org/gnome/shell/dbus-interfaces/' + iface + '.xml';
+    let f = Gio.File.new_for_uri(uri);
+
+    try {
+        let [ok, bytes] = f.load_contents(null);
+        if (bytes instanceof Uint8Array)
+            xml = imports.byteArray.toString(bytes)
+        else
+            xml = bytes;
+    } catch (e) {
+        log('Failed to load D-Bus interface ' + iface);
+    }
+
+    return xml;
+}